#include "CImg.h"
using namespace cimg_library;

extern "C" void disp_img(unsigned char* data, int w, int h, int stride)
{
	CImg<unsigned char> image(w, h, 1, 3);
	for(int j=0;j<h;j++)
		for (int i = 0; i < w; i++) {
			image(i, j, 0) = data[j*stride + 3 * i];
			image(i, j, 1) = data[j*stride + 3 * i + 1];
			image(i, j, 2) = data[j*stride + 3 * i + 2];
		}
	image.display();
}

CImgDisplay main_disp;

extern "C" void show_img(unsigned char* data, int w, int h, int stride)
{
	CImg<unsigned char> image(w, h, 1, 3);
	for (int j = 0; j<h; j++)
		for (int i = 0; i < w; i++) {
			image(i, j, 0) = data[j*stride + 3 * i];
			image(i, j, 1) = data[j*stride + 3 * i + 1];
			image(i, j, 2) = data[j*stride + 3 * i + 2];
		}
	main_disp.display(image);
}

extern "C" void gen_text(const char* file_out, int text_size)
{
	FILE* pf = fopen(file_out, "w");
	for (int i = 0; i < 10; i++) {
		CImg<unsigned char> image(25, 47, 1, 1);
		image.fill(0);
		char c[2];
		unsigned char purple[] = { 255 };
		sprintf(c, "%d", i);
		image.draw_text(0, 0, c, purple, 0, 1, 53);
		fprintf(pf, "char textcode_%d[] = {\n", i);
		for (int k = 0; k < image.height(); k++) {
			for (int j = 0; j < image.width(); j++) {
				if (image(j, k) == 255) {
					fprintf(pf, "1, ");
				}
				else {
					fprintf(pf, "0, ");
				}
			}
		}
		fprintf(pf, "};\n");
		image.display();
	}
	fclose(pf);
}